﻿// ****************************************************************
// Copyright 2012, Stephan Burguchev
// e-mail: me@sburg.net
// ****************************************************************
// *
using System.Reflection;
using System.Windows;
using Updater.Utils;

namespace Updater.Wpf
{
    public class WpfMessageBoxService : IMessageBoxService
    {
        public WpfMessageBoxService()
        {
        }

        public WpfMessageBoxService(Window owner)
        {
            this.Owner = owner;
        }

        public Window Owner { get; set; }

        public bool? AskYesNoCancelQuestion(string text, string caption = null)
        {
            MessageBoxResult ret = MessageBox.Show(
                this.Owner,
                text,
                caption,
                MessageBoxButton.YesNoCancel,
                MessageBoxImage.Question);
            switch (ret)
            {
            case MessageBoxResult.Yes:
                return true;
            case MessageBoxResult.No:
                return false;
            default:
                return null;
            }
        }

        public bool AskYesNoQuestion(string text, string caption)
        {
            MessageBoxResult ret = MessageBox.Show(
                this.Owner,
                text,
                caption,
                MessageBoxButton.YesNo,
                MessageBoxImage.Question);
            return ret == MessageBoxResult.Yes;
        }

        public void Error(string text)
        {
            MessageBox.Show(
                this.Owner,
                text,
                new AssemblyAttributesReader(Assembly.GetEntryAssembly()).AssemblyTitle,
                MessageBoxButton.OK,
                MessageBoxImage.Error);
        }
    }
}
